# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jhkim

import numpy
import h5py


def h5py_save(hdf_path, comp_array, compression):
  with h5py.File(hdf_path, 'w') as hdf5:
    if comp_array.dtype.char == 'U':
      comp_array = numpy.core.defchararray.encode(comp_array, 'utf-8')
    elif comp_array.dtype.char == 'S':
      comp_array = numpy.array(comp_array.tolist())
    hdf5.create_dataset("arr_0", data=comp_array, compression=compression)


def h5py_load(hdf_path):
  with h5py.File(hdf_path, mode='r', driver='core', backing_store=False) as h5file:
    return h5file['arr_0'][:]
